package mock_seed

import (
	"wms/internal/model"
	"wms/pkg/database"
	"wms/pkg/logger"

	"go.uber.org/zap"
)

// InitFrozenFoodUnits 初始化餐饮冻品相关计量单位
func InitFrozenFoodUnits() error {
	logger.Info("开始初始化餐饮冻品相关计量单位...")
	db := database.GetDB()

	// 餐饮冻品计量单位列表
	units := []model.Unit{
		{
			Name:   "箱",
			Code:   "BOX",
			Status: 1,
			Remark: "冷链行业主要包装单位，通常为纸箱或泡沫箱，适合批量冷冻食品存储运输",
		},
		{
			Name:   "件",
			Code:   "PIECE",
			Status: 1,
			Remark: "计件单位，适用于整块冻肉、整只冻鸡、整条鱼等不规则单品",
		},
		{
			Name:   "盒",
			Code:   "CASE",
			Status: 1,
			Remark: "盒装单位，适用于小规格包装的冷冻食品，如冻虾、冻鱼片等",
		},
		{
			Name:   "袋",
			Code:   "BAG",
			Status: 1,
			Remark: "袋装单位，适用于速冻饺子、冻肉丸等小包装产品",
		},
		{
			Name:   "桶",
			Code:   "BUCKET",
			Status: 1,
			Remark: "桶装单位，主要用于冰淇淋、冻酸奶等冷冻乳制品",
		},
		{
			Name:   "托盘",
			Code:   "PALLET",
			Status: 1,
			Remark: "冷链物流常用单位，一个托盘通常装载多个箱，适合冷库大批量存储",
		},
		{
			Name:   "块",
			Code:   "BLOCK",
			Status: 1,
			Remark: "适用于大块冻肉、整块冰鲜等大体积冷冻食品",
		},
		{
			Name:   "条",
			Code:   "STRIP",
			Status: 1,
			Remark: "适用于条状冷冻食品，如冻鱼条、冻肉条等",
		},
		{
			Name:   "板",
			Code:   "PLATE",
			Status: 1,
			Remark: "板块状冷冻食品单位，如冻鱼排、肉排等",
		},
		{
			Name:   "包",
			Code:   "PACK",
			Status: 1,
			Remark: "小包装冷冻食品，如速冻水饺、汤圆小包装",
		},
		{
			Name:   "罐",
			Code:   "CAN",
			Status: 1,
			Remark: "罐装冷冻或冷藏食品，如冰淇淋罐、冻奶油罐等",
		},
	}

	// 添加计量单位
	for _, unit := range units {
		if err := db.FirstOrCreate(&unit, model.Unit{Code: unit.Code}).Error; err != nil {
			logger.Error("创建计量单位失败", zap.String("code", unit.Code), zap.Error(err))
			return err
		}
	}

	logger.Info("餐饮冻品相关计量单位初始化成功")
	return nil
}
